<template>
	<!-- :filter-node-method="filterNode" -->
	<el-tree-select
		:data="deptList"
		filterable
		:render-after-expand="false"
		:props="{
			children: 'children',
			label: 'deptName',
			value: 'id',
			isLeaf: 'leaf'
		}"
	>
		<template #default="{ node, data }">
			<div v-if="data.type == 0">{{ node.label }}</div>
			<div v-else><my-icon icon="UserFilled" /> {{ node.label }}</div>
		</template>
	</el-tree-select>
</template>

<script setup name="MyDeptUserSelect">
import { getDeptUser } from '@a/public';

const deptList = ref([]);
getDeptUser().then((res) => {
	deptList.value = deleteEmpty(res.data);
});

function deleteEmpty(list) {
	for (let i = list.length - 1; i >= 0; i--) {
		const item = list[i];
		if (item.type == 0 && item.hasChildren == false) {
			list.splice(i, 1);
			continue;
		}
		if (item.children?.length > 0) deleteEmpty(item.children);
	}
	return list;
}
</script>
